local TypeHelper = {}

TypeHelper.TYPE_ITEM = 1
TypeHelper.TYPE_EQUIPMENT = 2
TypeHelper.TYPE_MAGICKEY = 3
TypeHelper.TYPE_GENSTONE = 4
TypeHelper.TYPE_RESOURCE = 5
TypeHelper.TYPE_HERO = 6

function TypeHelper.getRes(type, value)
    local typeCfg = require("config.type_manage").get(type)
    assert(typeCfg, "can not found cfg in type_manage by id=" .. type)
    local cfg = require("config." .. typeCfg.name).get(value)
    assert(cfg, "can not found cfg in " .. typeCfg.name .. " by id=" .. value)
    local retFunc = TypeHelper["_type_" .. typeCfg.name]
    printDebug(typeCfg.name)
    local param = {}
    param.cfg = cfg
    param.type = type
    param.value = value
    if retFunc then
        retFunc(param)
    end
    return param
end

function TypeHelper.getCfg(type, value)
    local typeCfg = require("config.type_manage").get(type)
    assert(typeCfg, "can not found cfg in type_manage by id=" .. type)
    local cfg = require("config." .. typeCfg.name).get(value)
    assert(cfg, "can not found cfg in " .. typeCfg.name .. " by id=" .. value)
    return cfg
end

function TypeHelper.getTypeName(type)
    local typeCfg = require("config.type_manage").get(type)
    assert(typeCfg, "can not found cfg in type_manage by id=" .. type)
    return typeCfg.name
end

function TypeHelper._type_items(param)
    param.name = param.cfg.name
    param.desc = ""
    param.icon_bg = G_ResourceManager:loadSprite("ItemAltas", "frame")
    param.icon = G_ResourceManager:loadSprite("ItemAltas", param.cfg.res)
end

function TypeHelper._type_equipment(param)
    param.desc = param.cfg.desc
    param.name = param.cfg.name
    param.icon_bg = G_ResourceManager:loadSprite("EquipAltas", "frame")
    param.icon = G_ResourceManager:loadSprite("EquipAltas", param.cfg.res)
end

function TypeHelper._type_magickey(param)
    param.desc = param.cfg.desc
    param.name = param.cfg.name
    param.icon_bg = G_ResourceManager:loadSprite("MagickeyAltas", "frame")
    param.icon = G_ResourceManager:loadSprite("MagickeyAltas", param.cfg.res)
end

function TypeHelper._type_gemstone(param)
end

function TypeHelper._type_resource(param)
    printDebug("TypeHelper._type_resource " .. param.cfg.id .. " res " .. param.cfg.res)
    param.desc = ""
    param.name = param.cfg.name
    param.icon_bg = G_ResourceManager:loadSprite("ResourceAtlas", "frame")
    param.icon = G_ResourceManager:loadSprite("ResourceAtlas", param.cfg.res)
    printDebug(param.icon)
end

function TypeHelper._type_hero(param)
    param.desc = param.cfg.desc
    param.name = param.cfg.name
    param.icon_bg = G_ResourceManager:loadSprite("HeroAltas", "frame")
    local heroRes = require("config.hero_res").get(param.cfg.res_id)
    param.icon = G_ResourceManager:loadSprite("HeroAltas", heroRes.icon)
end

return TypeHelper
